package models;

import java.sql.ResultSet;
import java.sql.SQLException;

import com.trackvoodoo.models.TrackPictureDocument.TrackPicture;
import com.trackvoodoo.models.TrackPicturesDocument.TrackPictures;

import database.connector.DatabaseFactory;
import database.live.DOAStatements;
import database.live.MySqlDAO;

public class TrackPicturesModel {

	private MySqlDAO d = null;
	private TrackPictures tPics = null;
	
	public TrackPicturesModel()
	{
		d = (MySqlDAO) DatabaseFactory.getDAO();
		if (d.isOpen())
		{
			try{
				tPics = TrackPictures.Factory.newInstance();
				ResultSet rs = d.selectQuery(DOAStatements.SELECT_TRACK_PICTURES); //idpictures, trackRef, trackOverview, location, picture
				while (rs.next())
				{
					TrackPicture p = tPics.addNewTrackPicture();
					p.setIdpictures(rs.getInt(1));
					p.setTrackRef(rs.getInt(2));
					p.setTrackOverview(rs.getString(3));
					p.setLocation(rs.getString(4));
					p.setPicture(rs.getString(5));
				}
			}catch (SQLException e)
			{
				e.printStackTrace();
			}finally
			{
				d.closeConnection();
			}
		}
	}
	
	public TrackPictures getTrackPictures()
	{
		return tPics;
	}
}
